<template>
<div>
    <div @click="getcollecteds(goodsId)">
        <slot>
            <i class="iconfont icon-gou_wu_che2"></i>
        </slot>
    </div>
    <div class="shoppingShow" v-if="car">
                <div class="shoppingShow-header" @click="shoppingCar"></div>
                <div class="shoppingShow-content">
                    <div class="shoppingShow-content-top">
                        <img :src="urlImg[0]" alt="">
                        <div class="shoppingShow-content-top-title">
                            <p>{{result.goodsName}}</p>
                            <div class="shopping-money">
                                ￥<span class="spn">{{result.orderPrice}}</span>
                                <span class="spns">{{result.minimumOrderQuantity}}{{result.quantityUnit}}起批</span>
                            </div>
                        </div>
                        <img class="quxiao" src="../assets/quxiao.png" alt="" @click="shoppingCar">
                    </div>
                    <div class="shoppingShow-content-dan">
                        <span>库存{{results.skuSaleNum}}{{result.measurementUnit}}</span>
                        <span>月销{{results.salesNum}}{{result.measurementUnit}}</span>
                        <span>{{result.integerZeroConvert}}</span>
                    </div>
                    <div class="shoppingShow-content-count">
                        <p>数量</p>
                        <div class="shoppingShow-content-count-right">
                            <p :class="activeBoo&&'active'" @click="select">{{result.secondMeasurementUnit}}</p>
                            <p :class="!activeBoo&&'active'" @click="select">{{result.measurementUnit}}</p>
                            <button @click="con">+</button>
                            <input type="text" :value="result.ratio1">
                            <button @click="cons">-</button>
                        </div>
                    </div>
                    <div class="bottom bottoms" v-if="results.skuSaleNum">
                        <div class="bottom-money">合计:<span>￥{{Price}}</span></div>
                        <div class="bottom-right" @click="getJoin(goodsId)">加入购物车</div>
                    </div>
                    <div class="bottom bottoms" v-else>
                        <div class="bottom-money">合计:<span>￥{{Price}}</span></div>
                        <div class="bottom-buhuo">补货中</div>
                    </div>
                </div>
    </div>
</div>
</template>
<script>
export default {
    props:['goodsId'],
    data(){
        return{
            skuid:'',
            activeBoo:false,
            result:[],
            results:'',
            urlImg:[],
            car:false
        }
    },
    methods:{
        con(){
            if(this.result.ratio1>=this.results.skuSaleNum){
                console.log('库存不足')
            }else{
                this.result.ratio1+=1
            }
            
        },
        cons(){
            if(this.result.ratio1!=0){
                this.result.ratio1-=1
            }         
        },
        getcollecteds(goodsId){
            let headers;
            if (this.$store.state.token) {
                headers = {
                token: this.$store.state.token,
                userId: this.$store.state.userInfo.id
                };
            } else {
                headers = {};
            }
            let skuids=goodsId
            let stationId=this.$store.state.stationId
            let userId=this.$store.state.userInfo.id
            let shopId=this.$store.state.storeId.storeId
            let merchantId=this.$store.state.merchantInfo.merchantId
            let storeId=this.$store.state.storeId.id
            console.log(skuids,stationId,userId)
            this.$http.get("https://web-gateway.newbeescm.com/b2b-app-web/goodsDetail/"+goodsId+'/'+stationId+'/'+userId+'/'+shopId+'/'+merchantId+'/'+storeId,
                {
                    headers,
                })
                .then(res => {
                    console.log(res)
                if(res.data.status.statusCode===0){
                    console.log(this.car)
                    console.log(res.data.result.goodsOl)
                    if(res.data.result.goodsOl){
                         this.result = res.data.result.goodsOl;
                         this.results = res.data.result;
                         this.urlImg = res.data.result.goodsOl.picsUrl.split(",")
                        //  console.log(this.results)
                        //  console.log(111)
                         this.car=true;
                         
                    }          
                }                
                })
                .catch(err => {
                    console.log(err);
                });
        },
        getJoin(goodsId){
            let headers;
            if (this.$store.state.token) {
                headers = {
                token: this.$store.state.token,
                userId: this.$store.state.userInfo.id
                };
            } else {
                headers = {};
            }
            this.$http.post("https://web-gateway.newbeescm.com/b2b-app-web/join",
                {
                    choiceOrNo:true,
                    cityId:this.$store.state.merchantInfo.cityId,
                    countyId:this.$store.state.storeId.county,
                    dealerId:this.result.dealerId,
                    dealerOrgId:this.result.dealerOrgId,
                    firstQuantity:this.result.ratio1,
                    firstUnit:this.result.measurementUnit,
                    merchantId:this.$store.state.merchantInfo.merchantId,
                    provId:this.$store.state.merchantInfo.provinceId,
                    secondQuantity:0,
                    secondUnit:this.result.secondMeasurementUnit,
                    shopId:this.$store.state.storeId.storeId,
                    siteId:this.$store.state.stationId,
                    skuId:goodsId,
                    storeId:this.$store.state.storeId.id,
                    streetId:this.$store.state.storeId.town,
                    thirdQuantity:0,
                    thirdUnit:"",
                    userId:this.$store.state.userInfo.id,
                },
                {
                    headers, 
                })
                .then(res => {
                    console.log(res);
                    if(res.data.status.statusCode===0){
                        this.$store.commit('setgood',res.data.result)
                    }
                this.$router.push('/shopping')       
                })
                .catch(err => {
                    console.log(err);
                });
        },
        select(){
            this.activeBoo=!this.activeBoo
        },
        shoppingCar(){
            this.car = false;
        },
        // shoppingHide(){
        //     this.car = false;
        // },
    },
    mounted(){
        this.skuid=this.$route.query.skuid
    },
    computed:{
        Price(){
            return this.result.orderPrice*this.result.ratio1
        }
        
    }
        
}
</script>
<style scoped lang="scss">
.icon-gou_wu_che2{
    color: #dd3333;
    font-size: 0.16rem;
}
.shoppingShow{
    position: fixed;
    top: 0.43rem;
    left: 0;
    right: 0;
    z-index: 1000;
    bottom: 0.49rem;
    display: grid;
    grid-template-rows: 1rem 1fr;
    .shoppingShow-header{
        background: #000;
        opacity: 0.5;
    }
    .shoppingShow-content{
        background: #fff;
        .shoppingShow-content-top{
            padding: 0.14rem;
            display: flex;
            justify-content: space-between;
            img{
                width: 1.06rem;
                height: 1.06rem;
            }
            .shoppingShow-content-top-title{
                p{
                    font-size: 0.14rem;
                    margin-top: 0.1rem;
                    margin-bottom: 0.12rem;
                }
                .shopping-money{
                    font-size: 0.12rem;
                    color: #dd3333;
                    .spn{
                        font-size: 0.2rem;
                        margin-left: 0.05rem;
                    }
                    .spns{
                        color: #666;
                        margin-left: 0.1rem;
                    }
                }
            }
            .quxiao{
                width: 0.12rem;
                height: 0.12rem;
            }
        }
        .shoppingShow-content-dan{
            padding-left: 0.14rem;
            padding-bottom: 0.1rem;
            position: relative;
            span{
                font-size: 0.12rem;
                color: #999;
                margin-right: 0.2rem;
            }
        }
        .shoppingShow-content-dan::after{
            content: "";
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 1px;
            background: #E1E1E1;
            transform: scale(1,0.5);
        }
        .shoppingShow-content-count{
            padding: 0.1rem 0.14rem;
            display: flex;
            justify-content: space-between;
            p{
                font-size: 0.14rem;
                color: #999;
            }
            .shoppingShow-content-count-right{
                display: flex;
                p{
                    width: 0.28rem;
                    height: 0.28rem;
                    text-align: center;
                    line-height: 0.25rem;
                    border: 1px solid #9b9b9b;
                    color: #333;
                    font-size: 0.12rem;
                    border-radius: 0.03rem;
                    box-sizing: border-box;
                    margin-right: 0.1rem;
                }
                .active{
                    color: #fff;
                    background: #dd3333;
                }
                button{
                    width: 0.28rem;
                    height: 0.28rem;
                    text-align: center;
                    line-height: 0.25rem;
                    // color: #fff;
                }
                input{
                    width: 0.51rem;
                    height: 0.26rem;
                    border: none;
                    border-top: 1px solid #9b9b9b;
                    border-bottom: 1px solid #9b9b9b;
                    text-align: center;
                }
            }
        }
    }
}
.bottom{
    height: 0.49rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: rgba(255,255,255,0.90);
    box-shadow: inset 0 0 0 0 #E1E1E1;
    z-index: 99;
    .bottom-left{
        display: flex;
        flex: 1;
        justify-content: space-around;
        li{
            .icon-jinrudianpu,.icon-shoucang,.icon-gou_wu_che2{
                font-size: 0.18rem;
                color: #666;
            }
            p{
                font-size: 0.11rem;
                color: #666;
            }
        }
    }
    .bottom-right{
        width: 1.2rem;
        height: 0.49rem;
        color: #fff;
        line-height: 0.49rem;
        text-align: center;
        background: #dd3333;
    }
    .bottom-buhuo{
        width: 1.2rem;
        height: 0.49rem;
        color: #fff;
        line-height: 0.49rem;
        text-align: center;
        background: #ccc;
    }
}
.bottoms{
    justify-content: flex-end;
    .bottom-money{
        span{
            color: #dd3333;
            padding-left: 0.1rem;
            padding-right: 0.2rem;
        }
    }
    .bottom-buhuo{
        width: 1.2rem;
        height: 0.49rem;
        color: #fff;
        line-height: 0.49rem;
        text-align: center;
        background: #ccc;
    }
}
</style>
